//
//  DetailTableViewCell.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/6/30.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "DetailTableViewCell.h"


@interface DetailTableViewCell ()


@property (nonatomic, strong)UILabel * dateLabel;

@property (nonatomic, strong)UILabel * timeLabel;

@property (nonatomic, strong)UILabel * subTltleLabel;

@property (nonatomic, strong)UILabel * moneyLabel;

@property (nonatomic, strong)UIView * lineView;

@end

@implementation DetailTableViewCell


//  增长颜色
#define RED_COLOR   ColorWithRGB(0xf25167)
#define GREEN_COLOR  ColorWithRGB(0x00c55b)

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setupUI{
    
    self.backgroundColor = [UIColor clearColor];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    self.dateLabel = [UILabel new];
    
    self.dateLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    self.dateLabel.textColor = ColorWithRGB(0xffffff);
    self.dateLabel.textAlignment = NSTextAlignmentLeft;
    
    [self addSubview:self.dateLabel];
    
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(15 * SCREENH6);
        make.top.mas_equalTo(self).offset(20 * SCREENH6);
    }];
    
    
    self.timeLabel = [UILabel new];
    
    self.timeLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12 * SCREENH6];
    self.timeLabel.textColor = ColorWithRGB(0xa6a6a6);
    self.timeLabel.textAlignment = NSTextAlignmentLeft;
    
    [self addSubview:self.timeLabel];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.dateLabel);
        make.top.mas_equalTo(self.dateLabel.mas_bottom);
    }];
    
    
    self.subTltleLabel = [UILabel new];
    
    self.subTltleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13 * SCREENH6];
    self.subTltleLabel.textColor = RED_COLOR;
    self.subTltleLabel.textAlignment = NSTextAlignmentRight;
    
    [self addSubview:self.subTltleLabel];
    
    [self.subTltleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.centerY.mas_equalTo(self);
    }];
    
    
    self.moneyLabel = [UILabel new];
    
    self.moneyLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13 * SCREENH6];
    self.moneyLabel.textColor = RED_COLOR;
    self.moneyLabel.textAlignment = NSTextAlignmentRight;
    
    [self addSubview:self.moneyLabel];
    
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.subTltleLabel);
        make.trailing.mas_equalTo(self).offset(-15 * SCREENH6);
    }];
    
    self.lineView = [UIView new];
    
    self.lineView.backgroundColor = [UIColor whiteColor];
    self.lineView.alpha = 0.1;
    
    [self addSubview:self.lineView];
    
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(self);
        make.height.mas_equalTo(1 * SCREENH6);
    }];
    
}



- (void)setModel:(TraderInfoModel *)model{
    
    _model = model;
    
    NSString * DateAndTime = [NSString stringWithFormat:@"%@",model.time];
    NSString * moneyString = [NSString stringWithFormat:@"%@",model.amount];
    //出入金类型：Deposit, Withdraw
    NSString * changeTypeString = [NSString stringWithFormat:@"%@",model.fundingType];
    
    NSString * dateString = [DateAndTime substringToIndex:10];
    NSString * timeStr = [DateAndTime substringFromIndex:11];
    NSString * timeString = [timeStr substringToIndex:8];
    
    if ([changeTypeString isEqualToString:@"Withdraw"]) {
        //subTltleLabel
        self.subTltleLabel.textColor = GREEN_COLOR;
        self.subTltleLabel.text = @"出金";
        
        self.moneyLabel.textColor = GREEN_COLOR;
        self.moneyLabel.text = [NSString stringWithFormat:@"-$%@",moneyString];
    }else{
        
        self.subTltleLabel.textColor = GREEN_COLOR;
        self.subTltleLabel.text = @"入金";
        
        self.subTltleLabel.textColor = RED_COLOR;
        self.moneyLabel.text = [NSString stringWithFormat:@"+$%@",moneyString];
    }
    
    self.dateLabel.text = dateString;
    self.timeLabel.text = timeString;
    
    
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
